<?php
	date_default_timezone_set('Asia/shanghai');  //获取当前时区
	
	session_start();

    //动态获取用户访问的路径中的文件名称   basename:必选参数1获取用户访问的路径包含后缀以及路径 参数二可选。规定文件扩展名。如果文件有名有文件扩展名，将不会显示这个扩展名。
    // cms/news_list.php
    //$_filename ==news_list

    //index.php?c=admin&a=login&admin=1


	 $_filename = $a ;
 
	//如果勾选了自动登录且用户访问的不是登录页面则直接跳转到用户访问的页面
	if ($_filename !='login' && empty($_SESSION['admin']) && !empty($_COOKIE['username']) && !empty($_COOKIE['password']) && !empty($_COOKIE['auto'])) {
		 
		$_SESSION['admin']['username'] = $_COOKIE['username'];
	    header('Location:'.$_filename.'.php');
	}

	//如果勾选了自动登录且用户访问的是登录页面则强制跳转到后台首页
	if($_filename=='login' && !empty($_COOKIE['username']) && !empty($_COOKIE['auto']) && empty($_GET['out'])){
		$_SESSION['admin']['username'] = $_COOKIE['username'];
		header('Location:index.php');
	}
  

	// print_r($_SERVER);die;




	 
// print_r($admin);die;

	
if (empty($_SESSION['admin']) && $_filename != 'login' && $admin != 'home/' && $_filename != 'logout' ) {
		    echo '<script>alert("请先登录");location.href="index.php?c=admin&a=login&admin=1";</script>';
	    die;
	}

	if($admin!='home/'){
		$_filename= VIEW_PATH.$admin.'/'.$c.'/'.$a.'.html';
	}else{
		 $_filename= VIEW_PATH.$admin.$c.'/'.$a.'.tpl';
	}
	 
	// $_filename= VIEW_PATH.$admin.'/'.$c.'/'.$a.'.html';

// print_r($_SESSION['admin']);die;

	//$link数据库对象 mysqli_query运行数据命令
	
	include LIB_PATH.'my_db.php';
	$link=db_connect();
	// 	if (!empty($_SESSION['admin'])) {
	// 		$rule=$c.'/'.$a;
	// 		//获得权限表的Id
	// 		$power_id=selectone('power',"rule='$rule'")['id'];
	// 		// print_r($power_id);die;
	// 	$no_check=array('index','logout','login','code');
	// 	if(!in_array($power_id, $_SESSION['admin']['power']) && !in_array($a, $no_check)){
	// 		echo '<script>alert(无权限);history.go(-1);</script>';die;
			
	// 	}	
	   
	// }

	include LIB_PATH.'pages.php';

	include LIB_PATH.'file.php';

	include LIB_PATH.'cate_fun.php';
 
	require_once(LIB_PATH . 'smarty/Smarty.class.php');//加载smarty类文件

	$smarty = new Smarty();//实例化smarty类对象

	$smarty->template_dir = VIEW_PATH;//模版(视图)路径

	$smarty->compile_dir  = VIEW_PATH.'templates_c/';//smarty编译文件路径

	$smarty->cache_dir    = VIEW_PATH.'cache/';//缓存目录路径

	$smarty->left_delimiter='<{';

	$smarty->right_delimiter='}>';

	$smarty->assign('filename',$_filename);

	$smarty->caching=2;

	$smarty->cache_lifetime=60;




	

 

